﻿function UserController($scope, UserFactory, $location) {
    $scope.registerUser = function () {
        if ($scope.newUser.password === $scope.newUser.confirmPassword && $scope.newUser.password) {
            UserFactory.register({
                username: $scope.newUser.username,
                email: $scope.newUser.email,
                password: $scope.newUser.password
            }).then(function (data) {
                console.log(data);
                $location.path('/')
            }, function (data) {
                console.log(data);
            })
        }
        else {
            $scope.newUser.password = $scope.newUser.confirmPassword = '';
            alert("Your passwords must match");
        }
    }
    $scope.getUser = function () {
        UserFactory.getUser().then(function (data) {
            $scope.editUser = data;
        });
    }
}
UserController.$inject = ['$scope', 'UserFactory', '$location'];
